package bishi.alibaba._bishi2;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/05/21 18:44
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        sc.nextLine();
        while (T > 0) {
            int n = sc.nextInt();
            int q = sc.nextInt();
            sc.nextLine();
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) {
                nums[i] = sc.nextInt();
            }
            sc.nextLine();
            while (q > 0) {
                int x = sc.nextInt();
                int k = sc.nextInt();
                sc.nextLine();
                System.out.println(Arrays.toString(nums));
                System.out.println(x + "  " + k);
                if (x < 0) {
                    for (int i = 0; i < n; i++) {
                        if (k == nums[i]) {
                            System.out.println(i - x);
                        }
                    }
                } else if (x >= n) {
                    for (int i = n - 1; i >= 0; i--) {
                        if (k == nums[i]) {
                            System.out.println(i - x);
                        }
                    }
                } else {
                    int left = x - 1;
                    int right = x;
                    while (left >= 0 || right < n) {
                        if (right < n) {
                            if (nums[right] == k) {
                                System.out.println(Math.abs(right - x));
                                break;
                            }
                            right++;
                        }
                        if (left >= 0) {
                            if (nums[left] == k) {
                                System.out.println(Math.abs(left - x));
                                break;
                            }
                            left--;
                        }
                    }
                    if (left == -1 && right == n) {
                        System.out.println(-1);
                    }
                }
                q--;
            }
            T--;
        }
    }
}
